#ifndef ABSTRCTITEMMODEL_H
#define ABSTRCTITEMMODEL_H


#include "itemmodel_global.h"
#include "modelitem.h"


#include <QObject>
#include <QAbstractItemModel>
#include <QPointer>


class ITEMMODELSHARED_EXPORT ItemTreeModel : public QAbstractItemModel
{
    Q_OBJECT

public:

    enum Role
    {
        Role_FIRST = Qt::UserRole + 1,

        Role_PATH = Role_FIRST,
        Role_SORT,
        Role_TYPE,

        Role_LAST = Role_TYPE
    };

    ItemTreeModel(QObject* parent = 0);
    ItemTreeModel(ModelItem* root, QObject* parent);
    virtual ~ItemTreeModel();

    virtual QModelIndex index(int row, int column, const QModelIndex &parent) const;
    virtual QModelIndex parent(const QModelIndex &child) const;

    virtual int rowCount(const QModelIndex &parent) const;
    virtual int columnCount(const QModelIndex &parent) const;

    virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
    virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);

    virtual Qt::ItemFlags flags(const QModelIndex &index) const;

    void setRoot(ModelItem* root);
    ModelItem* root() const;

    bool isChanged() const;


protected slots:

    void onChanged(bool changed = true);


protected:

    static ModelItem* itemFromIndex(const QModelIndex& index);

    QPointer<ModelItem> m_root;
    bool m_changed;



};

#endif // ABSTRCTITEMMODEL_H
